package cn.dd.crmweb.oss.controller;


import cn.dd.crmweb.oss.service.IOssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/oss")
public class OssController {

    @Autowired
    private IOssService ossService;



    //批量下载
    @GetMapping("downloads")
//    @PostMapping("downloads")
    public void downloadSource(HttpServletResponse response) {

        List<String> list = new ArrayList<>();

//        for (String audio : audios) {
////            list.add(audio);
//            System.out.printf("wode" + audio);
//        }
        list.add("dataset/audio/0001.mp3");
        list.add("dataset/audio/0002.mp3");
        list.add("dataset/audio/0003.mp3");
        list.add("dataset/audio/0004.mp3");
        list.add("dataset/audio/0005.mp3");
        String zipFileName = "test";
        ossService.batchDownLoadOssFile(list, zipFileName, response);
    }


    //下载全部
    @GetMapping("downloadall")
//    @PostMapping("downloads")
    public void downloadAll(HttpServletResponse response) {

        List<String> list = new ArrayList<>();
        for (int i=1 ;i<=6823 ;i++) {
            if (i<10) {
                list.add("dataset/audio/000"+ i +".mp3");
            }else if(10 <= i && i < 100){
                list.add("dataset/audio/00"+ i +".mp3");
            }else if(100 <= i && i<1000) {
                list.add("dataset/audio/0"+ i +".mp3");
            }else {
                list.add("dataset/audio/"+ i +".mp3");
            }
        }
        String zipFileName = "test";
        ossService.batchDownLoadOssFile(list, zipFileName, response);
    }
}